< Prev(J) / Next(K) > / View :

Filename: /text/sbasic/shared/03103500.xhp

(section: static) (bookmark: bm_id3149798)
Static statement

Static ステートメント

Static Statement [Runtime]
Static ステートメント [実行時](hd_id3149798.1)

Declares a variable or an array at the procedure level within a subroutine or a function, so that the values of the variable or the array are retained after exiting the subroutine or function. Dim statement conventions are also valid.
関数およびサブルーチン内で変数や配列を定義する際に、これらをプロシージャーレベルで再利用することを宣言して、該当する関数およびサブルーチンが終了しても、こうした変数や配列に代入した値を保持するようにします。ここでは Dim ステートメントと同様の規約が適用されます。(par_id3153311.2)

(/section: static)
Warning Icon 警告マーク The Static statement cannot be used to define variable arrays. Arrays must be specified according to a fixed size.
Static ステートメント は、配列変数の定義には使用できません。配列は固定サイズで定義する必要があります。(par_id3147264.3)

Syntax:
構文:(hd_id3149657.4)

Static VarName[(start To end)] [As VarType], VarName2[(start To end)] [As VarType], ...
Static VarName[(start To end)] [As VarType], VarName2[(start To end)] [As VarType], ...(par_id3150400.5)

Example:
例:(hd_id3148452.6)

Sub ExampleStatic
Sub ExampleStatic(par_id3156214.7)

Dim iCount as Integer, iResult as Integer
Dim iCount as Integer, iResult as Integer(par_id1940061.)

For iCount = 0 to 2
For iCount = 0 to 2(par_id878627.)

iResult = InitVar()
iResult = InitVar()(par_id7914059.)

Next iCount
Next iCount(par_id299691.)

MsgBox iResult,0,"The answer is"
MsgBox iResult,0,"The answer is"(par_id3150870.11)

End Sub
End Sub(par_id3153771.13)

REM Function for initialization of the static variable
REM スタティック変数の初期化用関数(par_id3151115.15)

Function InitVar() As Integer
Function InitVar() As Integer(par_id3148618.16)

Static iInit As Integer
Static iInit As Integer(par_id3154217.8)

Const iMinimum as Integer = 40 REM minimum return value of this function
Const iMinimum as Integer = 40 REM minimum return value of this function(par_id1057161.)

if iInit = 0 then REM check if initialized
if iInit = 0 then REM check if initialized(par_id580462.)

iInit = iMinimum
iInit = iMinimum(par_id7382732.)

else
else(par_id5779900.)

iInit = iInit + 1
iInit = iInit + 1(par_id3151041.10)

end if
end if(par_id5754264.)

InitVar = iInit
InitVar = iInit(par_id6529435.)

End Function
End Function(par_id3150487.18)


< Prev / Next >